package com.yumao.recyclerview;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/1.
 */

public class MyAdapter3 extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private LayoutInflater inflater;
    private List<Integer> list;

    public MyAdapter3(Context context) {
        inflater = LayoutInflater.from(context);
        list = new ArrayList<>();
        for (int i = 0; i < 40; i++) {
            int a = (int) (Math.random() * 3);
            list.add(a);
        }
    }

    @Override
    public int getItemCount() {
        return 40;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        RecyclerView.ViewHolder viewHolder = null;
        switch (viewType) {
            case 0:
                view = inflater.inflate(R.layout.recycler_item, parent, false);
                viewHolder = new MyAdapter3.ViewHolder1(view);
                break;
            case 1:
                view = inflater.inflate(R.layout.recycler_item11, parent, false);
                viewHolder = new MyAdapter3.ViewHolder2(view);
                break;
            case 2:
                view = inflater.inflate(R.layout.recycler_item111, parent, false);
                viewHolder = new MyAdapter3.ViewHolder3(view);
                break;
        }
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        //如果要绑定数据，绑定方法写在viewHolder中
    }

    @Override
    public int getItemViewType(int position) {
        return list.get(position);
    }

    private static class ViewHolder1 extends RecyclerView.ViewHolder {
        TextView textView;

        ViewHolder1(View itemView) {
            super(itemView);
            textView = (TextView) itemView;
        }
    }

    private static class ViewHolder2 extends RecyclerView.ViewHolder {
        TextView textView;
        ImageView imageView;

        ViewHolder2(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.name);
            imageView = (ImageView) itemView.findViewById(R.id.image);
        }
    }

    private static class ViewHolder3 extends RecyclerView.ViewHolder {
        TextView textView;
        TextView textView2;

        ViewHolder3(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.name);
            textView2 = (TextView) itemView.findViewById(R.id.age);
        }
    }
}
